<template>
    <div class="task_detail">
        <el-page-header @back="goBack" class="page-header">
            <template #content>
                <span class="text-large font-600 mr-3"> 详情 </span>
            </template>
            <template #extra>
                <div class="flex items-center">
                    <el-button type="primary" @click="toEdit" v-permission="'enact:table:edit'">编辑</el-button>
                    <el-button type="success" @click="toUpgrade" v-permission="'enact:table:upgrade'">升级</el-button>
                </div>
            </template>
        </el-page-header>
        <div class="info">
            <el-descriptions border label-width="150">
                <el-descriptions-item label="报表名称">{{ state.data.tableName }}</el-descriptions-item>
                <el-descriptions-item label="报表版本">{{ state.data.tableVersion }}</el-descriptions-item>
                <el-descriptions-item label="批次号">{{ state.data.batchNumber }}</el-descriptions-item>
                <el-descriptions-item label="采集对象">{{ !state.data.collectObj ? '' : (state.data.collectObj.code ==
                    'MANAGER' ?
                    (state.data.objLevel.des + state.data.collectObj.des) :
                    state.data.collectObj.des) }}</el-descriptions-item>
                <el-descriptions-item label="任务类型">{{ state.data.type?.des }}</el-descriptions-item>
                <el-descriptions-item label="生成时间">{{ state.data.createTime }}</el-descriptions-item>
                <el-descriptions-item label="采集对象明细" span="3">
                    <el-tag type="primary" v-for="item in state.data.objs" :key="item.id" class="tag">{{ item.objName
                        }}</el-tag>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div class="detail_table">
                <template v-slot:columns>
                    <el-table-column property="batchNumber" label="批次号" align="center" />
                    <template v-for="(item, index) in state.header" :key="index">
                        <el-table-column :property="item.field" :label="item.label" align="center" />
                    </template>
                    <el-table-column property="deptName" label="组织" align="center" />
                    <el-table-column property="createName" label="采集人" align="center" />
                    <el-table-column property="create_time" label="采集时间" align="center">
                        <template #default="scope">
                            {{ dayjs(scope.row.create_time).format('YYYY-MM-DD HH:mm:ss') }}
                        </template>
                    </el-table-column>
                </template>
            </Table>
        </div>
    </div>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue"
import { useRouter, useRoute } from 'vue-router'
import { detail } from '@/api/enact/task'
import Table from '@/components/Table.vue'
import { getTaskTableHeader, page as pageList } from '@/api/data/data'
import { tr } from "element-plus/es/locale"

const router = useRouter()
const route = useRoute()

const id = route.params.id
const state = reactive({
    dataLoad: false,
    headerLoad: false,
    data: {

    },
    header: [],
    form: {
        tableId: un
    }
})

const goBack = () => {
    router.push("/task-list")
}


const getData = () => {
    detail(id).then(data => {
        state.data = data
         state.dataLoad = true
    })
}

const getHeader = () => {
    getTaskTableHeader(id).then(data => {
        state.header.push(...data)
        state.headerLoad = true
        // nextTick(() => {
        // })
    })
}


onMounted(() => {
    getData()
    getHeader()
})


</script>
<style scoped lang="scss">
.task_detail {
    height: 100%;
    display: flex;
    flex-direction: column;

    .page-header {
        flex-shrink: 0;
    }

    .info {
        margin-top: 20px;
        flex-shrink: 0;
    }

    .detail_table {
        flex-grow: 1;
        margin-top: 20px;
    }

    .tag:not(:first-of-type) {
        margin-left: 5px;
    }
}
</style>
